package ioperations;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddOperation implements IOPeration{
    public void work(BookList bookList){
        int currentSize= bookList.getUsedSize();
        if(currentSize==bookList.getBooks().length){
            System.out.println("书架已满，无法完成插入操作");
            return;
        }
        System.out.println("新增图书...");
        Scanner scanner=new Scanner(System.in);
        System.out.println("输入你要添加的图书的书名: ");
        String name= scanner.nextLine();
        System.out.println("输入本书的作者: ");
        String author= scanner.nextLine();
        System.out.println("输入这本书的类型：");
        String type= scanner.nextLine();
        System.out.println("输入本书的价格: ");
        int price=scanner.nextInt();
        Book newbook=new Book(name,author,price,type);
        bookList.setBooks(bookList.getUsedSize(), newbook);
        bookList.setUsedSize(bookList.getUsedSize()+1);
        System.out.println("插入成功");
    }
}
